<template>
  <el-upload
    class="upload-demo"
    :action="'/intelligent_control_webservice_yb/' + url"
    :show-file-list="false"
    :headers="headers"
    name="fileName"
    list-type="text"
    :on-success="upSuccess"
  >
    <el-button>导入</el-button>
  </el-upload>
</template>
<script>
export default {
  name: "FileUpload",
  props: {
    url: { type: String, default: "" },
  },
  computed: {
    headers() {
      return {
        Authorization: window.localStorage.getItem("token"),
      };
    },
  },
  methods: {
    upSuccess(res) {
      if (res.code == 200) {
        this.$message({
          showClose: true,
          message: res.msg,
          type: "success",
        });
        this.$emit("onSubmit");
      } else {
        this.$message({
          showClose: true,
          message: res.msg,
          type: "error",
        });
      }
    },
  },
};
</script>
<style lang="less" scoped>
.upload-demo {
  margin-left: 10px;
  margin-right: 10px;
  width: 70px;
  height: 40px;
}
</style>